package com.wdd.libbase.base

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView

/**
 *
 * @ProjectName:    OwnTool
 * @Package:        com.wdd.libbase.base
 * @ClassName:      OwnRecyclerViewAdapter
 * @Description:     java类作用描述
 * @Author:         王丹丹
 * @CreateDate:     2019/12/21 22:23
 * @UpdateUser:     更新者
 * @UpdateDate:     2019/12/21 22:23
 * @UpdateRemark:   更新说明
 * @Version:        1.0
 */
abstract class OwnRecyclerViewAdapter<T>(context: Context, protected var mDatas: List<T>?) :
    RecyclerView.Adapter<OwnRecyclerViewAdapter.ViewHolder>() {


    protected val layoutInflater: LayoutInflater = LayoutInflater.from(context)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = layoutInflater.inflate(getLayoutId(), parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int {
        if (mDatas == null) return 0
        return mDatas!!.size
    }


    protected abstract fun getLayoutId(): Int

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view)
}